07. Python versions at Udacity
Python versions at Udacity
Most Nanodegree programs at Udacity will be (or are already) using Python 3 almost exclusively.
Why we're using Python 3
- Jupyter is switching to Python 3 only
- Python 2.7 is being retired
- Python 3 has been out for almost 10 years, and there are very few dependencies (and none in this Nanodegree) that are incompatible.
At this point, there are enough new features in Python 3 that it doesn't make much sense to stick with Python 2. You should write Python code for version 3. Read more here.
The main breakage between Python 2 and 3
For the most part, the Python 2 code will work with Python 3. Of course, most new features introduced with Python 3 versions won't be backward compatible. The place where your Python 2 code will fail most often is the print
statement. See the change in the syntax below:
# Print statement in Python 2
print "Hello", "world!"
# Print statement in Python 3
print("Hello", "world!")
If you want your print()
function to work in both Python 2 and 3 versions, you'll need to import the print_function
in your Python 2.6+ code. The print()
function was backported to Python 2.6+ through the __future__
module:
# Python 3 `print()` function can run in Python 2.6+ after an `import` statement.
# In Python 2.6+
from __future__ import print_function
print("Hello", "world!")
# Python 2 `print` statement cannot run in Python 3.
# The following line of code will NOT work in Python 3
print "Hello", "world!"